package week3.day16;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * @Author fengzihao
 * @Date 2024-04-30 19:33
 */
public class DaysByBirthday {
    public static void main(String[] args) throws ParseException {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = formatter.parse("2001-12-29");
        Date date2 = new Date();

        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(date1);
        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(date2);

        long millisecondsDiff = Math.abs(cal1.getTimeInMillis() - cal2.getTimeInMillis());
        // 将时间戳差值转换为天数
        long daysBetween = TimeUnit.DAYS.convert(millisecondsDiff, TimeUnit.MILLISECONDS);
        System.out.println("daysBetween = " + daysBetween);
    }
}
